#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s;
    cin >> s;

    int ret = 1e9;
    for (char ch = 'a'; ch <= 'z'; ch++)
    {
        int sum = 0;
        for (auto i : s)
        {
            sum += min(abs(i - ch), 26 - abs(i - ch));
        }
        ret = min(sum, ret);
    }

    cout << ret << endl;
    return 0;
}